package com.snb.play.dwebtoon.util;

import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
import android.content.ServiceConnection;
import android.os.IBinder;

public class BinderManager {
	public static String TAG = BinderManager.class.getSimpleName();
	public static final String PKG_NAME = "com.snb.play.dwebtoon";

	public void doBindService(Context aContext) {
		aContext.bindService(new Intent(aContext, DownloadService.class), mConnection, Context.BIND_AUTO_CREATE);
	}

	public void doUbBindService(Context aContext) {
		aContext.unbindService(mConnection);
	}

	public DownloadService getService() {
		return mBoundService;
	}

	public DownloadService mBoundService;
	public ServiceConnection mConnection = new ServiceConnection() {
		public void onServiceConnected(ComponentName className, IBinder service) {
			// This is called when the connection with the service has been
			// established, giving us the service object we can use to
			// interact with the service. Because we have bound to a explicit
			// service that we know is running in our own process, we can
			// cast its IBinder to a concrete class and directly access it.
			Logger.d(TAG, "D_W_S Conn");
			mBoundService = ((DownloadService.DownLoaderBinder) service).getService();
		}

		public void onServiceDisconnected(ComponentName className) {
			mBoundService = null;
			Logger.d(TAG, "D_W_S Dis Conn");
		}
	};
}
